class Solution:
    def answerString(self, word: str, numFriends: int) -> str:
        if numFriends == 1:
            return word
        n = len(word)
        m = n - numFriends + 1
        mx = "a"
        for v in word:
            if v > mx:
                mx = v
        ans = ""
        for i, v in enumerate(word):
            if v == mx:
                s = word[i : min(i + m, n) :]
                if s > ans:
                    ans = s
        return ans


s = Solution()
print(s.answerString("gh", 1))
